package cn.wolfcode.trip.app.interceptor;

import cn.wolfcode.trip.app.utils.UserContext;
import cn.wolfcode.trip.base.domain.User;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.logging.Handler;

public class CheckLoginInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //获取当前登录的对象
        User user = UserContext.getCurrentUser();
        if(user==null){
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
